
package code.codeworld.info.controller;


import code.codeworld.common.kits.Request;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import code.codeworld.common.kits.Result;
import code.codeworld.info.model.Info;
import code.codeworld.info.model.vo.InfoVo;
import code.codeworld.info.service.InfoService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;
import java.util.Objects;

/**
 * Info控制器
 *
 * @author freecode
 * @date 2023/10/26 00:20
 */
@CrossOrigin
@RequestMapping(Request.CODEWORLD_WEB)
@RestController
@Validated
public class InfoController {
    @Resource
    private InfoService infoService;

    /**
     * 获取Info分页
     *
     * @author freecode
     * @date 2023/10/26 00:20
     */
    @GetMapping("info/page")
    public Page<Info> page(InfoVo InfoVo) {

        return infoService.page(InfoVo);
    }

    /**
     * 获取Info集合
     *
     * @author freecode
     * @date 2023/10/26 00:20
     */
    @GetMapping("info/list")
    public Result<List<Info>> list(InfoVo infoVo) {
        if (Objects.isNull(infoVo.getUpdateTime())) {
            infoVo.setUpdateTime(new Date());
        }
        return Result.data(infoService.list(infoVo));
    }

    /**
     * 获取Info详情
     *
     * @author freecode
     * @date 2023/10/26 00:20
     */
    @GetMapping("info/detail")
    public Result<Info> detail(@Valid Info Info) {
        return Result.data(infoService.detail(Info));
    }

    /**
     * 编辑Info标记
     *
     * @author freecode
     * @date 2023/10/26 00:20
     */
    @PostMapping("info/editMark")
    public Result<String> editMark(@RequestBody @Valid Info Info) {

        return infoService.editMark(Info);
    }



}
